package everything.search.agents;

import everything.Flag;
import everything.WorldMap;
import everything.search.AgentState;
import everything.search.trees.GameTreeSearchMaxiMax;

public class IntelligentMaxiMaxAgent extends IntelligentAgent{

	public IntelligentMaxiMaxAgent(String name, String color, int x, int y,	WorldMap map, int plys, boolean memorize, int id) {
		super(name, color, x, y, map, plys, memorize, id);
	}
	
	@Override
	public void makeMove(){
		GameTreeSearchMaxiMax game = new GameTreeSearchMaxiMax(_map, _id, _opponent.getId());
		makeMove2(game);
	}
	
	public static double utility(int id, AgentState t, WorldMap map) {
		if (t.isTerminal()){
		//if (t.getRemainingMoves()==0){
			int myScore=0;
			Flag[] flags = t.getFlags();
			for (int i =0; i<flags.length; i++){
				if (flags[i].getOwner()==id){
					myScore+=flags[i].getValue();
				}
			}
			return myScore;
		}
		return estimation(id, t, map);
	}
	
	public static double estimation(int id, AgentState t, WorldMap map){
		FlagQueue[] flags = processFlags(id, t.getX(), t.getY(), t.getHealth(), t.getXOpponent(), t.getYOpponent(), t.getHOpponent(), t.getRemainingMoves(), t.getFlags(), map);
		return flags[0].currentScore + flags[0].totalScore;
	}
}
